package welsir;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import welsir.entity.dos.User;
import welsir.security.AuthUser;
import welsir.security.Token;
import welsir.security.token.base.AbstractTokenGenerate;
import welsir.util.TokenUtil;

/**
 * 用户Token生成器
 */
@Component
public class UserTokenGenerate extends AbstractTokenGenerate<User> {

    @Autowired
    private TokenUtil tokenUtil;

    @Override
    public Token createToken(User user, Boolean longTerm) {
        AuthUser authUser = new AuthUser(user.getUsername(), user.getUid(), longTerm);
        return tokenUtil.createToken(authUser);
    }

    @Override
    public Token refreshToken(String refreshToken) {
        return tokenUtil.refreshToken(refreshToken);
    }
}
